home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!usenet
- From: GHouck <hksys@teleport.com>
- Newsgroups: comp.lang.c
- Subject: Re: [Help] I can't find my error.
- Date: 23 Feb 1996 01:34:25 GMT
- Organization: systems hk
- Message-ID: <4gj5j2$eqm@maureen.teleport.com>
- References: <4ggvgr$1b2@aurora.engr.LaTech.edu>
- NNTP-Posting-Host: ip-pdx02-33.teleport.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22 (Windows; I; 32bit)
-
- pluu@engr.LaTech.edu (PL) wrote:
- >Could anyone please tell me why the following program won't work?
- >*********************************************************
- >#include <stdio.h>
- >main()
- >{
- > char name;
- > int age, next_age;
- >
- > printf("%s\n","Please enter your name and age: ");
- > scanf("%s%d\n", &name, &age);
- > next_age= age + 1;
- > printf("Hi, %s ,next year, you will be %d\n", name, next_age);
- >}
- >*********************************************************
- >
- Hi back!
- You need to dimension your 'name' string (array of characters) to allow
- for input of the name string. Also, change the scanf to use the address
- of the array (via its name):
-
- #define MAXNAMELEN 128 /* for example... */
- ...
- char name[MAXNAMELEN]; /* alloc an array of chars */
- ...
- scanf( "%s %d",name,&age ); /* remove '\n' and '&' operator */
-
- Hope I didn't make too many mistakes; there are sharks in the waters.
- Yours, Geoff Houck
-
-